package com.cosina.game.crystallight.engine;

import java.util.Iterator;
import java.util.LinkedList;

import android.graphics.Point;

import com.cosina.game.crystallight.MediaPlayerAdapter;
import com.cosina.game.crystallight.engine.util.Time;
import com.cosina.game.crystallight.model.battle.FrameObject;
import com.cosina.game.crystallight.model.crystal.Crystal;
import com.cosina.game.crystallight.model.crystal.Tower;
import com.cosina.game.crystallight.model.enemy.Enemy;
import com.cosina.game.crystallight.model.enemy.Ps;
import com.cosina.game.crystallight.ui.battle.BattleResource;

public class PsManager implements Time {
	public LinkedList<Ps> pses = new LinkedList<Ps>();
	public LinkedList<FrameObject> frameObjects = new LinkedList<FrameObject>();
	
	public void createHit(int x, int y){
		MediaPlayerAdapter.hitThree();
		frameObjects.add(new FrameObject(x, y, BattleResource.hit));
	}
	
	public void createExplosion(Point occurPlace){
		MediaPlayerAdapter.explosion2();;
		frameObjects.add(new FrameObject(occurPlace.x, occurPlace.y, BattleResource.explosion));
	}
	
	public void createPs(Tower tower, Enemy enemy, Crystal crystal){
		MediaPlayerAdapter.hitOne();
		pses.add(new Ps(tower,enemy,crystal));
	}

	
	@Override
	public void withTimeGo() {
		
		Iterator<FrameObject> foIter = frameObjects.iterator();
		while(foIter.hasNext()){
			FrameObject fo = foIter.next();
			fo.withTimeGo();
			if(fo.isOver()){
				foIter.remove();
			}
		}
		
		Iterator<Ps> psIter = pses.iterator();
		while(psIter.hasNext()){
			Ps ps = psIter.next();
			ps.withTimeGo();
			if(false == ps.alive){
				psIter.remove();
			}
		}
	}
}
